﻿using Lis.IDAL;
using Lis.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Lis.Repository
{
    public abstract class GenericRepository<T> : IGenericRepository<T> where T : class,new()
    {
        #region MyRegion
        public IBaseDal<T> CurrentDal { get; set; }

        public abstract void GetDal();//抽象方法，子类必须实现

        public GenericRepository()//基类的抽象方法
        {
            GetDal();//抽象方法
        } 
        #endregion

        #region 01，新增+bool Add(T t)
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="t">实体对象</param>
        /// <returns></returns>
        public bool Add(T t)
        {
            return CurrentDal.Add(t);
        } 
        #endregion

        #region 02，删除+bool Delete(T t)
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">主键id</param>
        /// <returns></returns>
        public bool Delete(T t)
        {
            return CurrentDal.Delete(t);
        } 
        #endregion

        #region 03，更新+bool Update(T t)
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="t">实体对象</param>
        /// <returns></returns>
        public bool Update(T t)
        {
            return CurrentDal.Update(t);
        } 
        #endregion

        #region 04，获取数据（分页）+IQueryable<T> GetEntitys(string pageIndex, string pageSize)
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="S"></typeparam>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="total">总条数</param>
        /// <param name="isAsc">是否倒序</param>
        /// <param name="whereLambda">查询lambda</param>
        /// <param name="orderByLambda">排序lambda</param>
        /// <returns></returns>
        public IQueryable<T> GetPageEntities<S>(int pageSize, int pageIndex, out int total, bool isAsc, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda)
        {
            return CurrentDal.GetPageEntities<S>(pageSize, pageIndex,out total, isAsc, whereLambda, orderByLambda);
        } 
        #endregion
    }
}
